package dto

import (
	"ginfast/app/mall/model"
	"ginfast/pkg/orm"
)

type Where struct {
	orm.DbPage
	OrderSn         string `form:"orderSn"`
	ReceiverKeyword string `form:"receiverKeyword"`
	OrderType       string `form:"orderType"`
	SourceType      string `form:"sourceType"` //
	Status          string `form:"status"`
	Phonenumber     string `form:"phonenumber"` // 手机号
	PayType         string `form:"payType"`     //
}

func (p *Where) DbModelWhere(v any, handles ...func(dw *orm.DbWhere)) *orm.DbWhere {
	w := p.DbWhere()
	switch v.(type) {
	case *model.Order:
		if p.ReceiverKeyword != "" {
			w.Add("ReceiverName like ? or ReceiverPhone like ?", p.ReceiverKeyword, p.ReceiverKeyword)
		}
		w.Like("OrderSn", p.OrderSn)
		w.EqualNumber("SourceType", p.SourceType)
		w.EqualNumber("OrderType", p.OrderType)
		w.EqualNumber("Status", p.Status)
	case *model.User:
		w.Like("Phonenumber", p.Phonenumber)
	case *model.Consumption:
		w.EqualNumber("PayType", p.PayType)
	}
	for _, h := range handles {
		h(w)
	}
	return w.Model(v)
}
